import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:yuanquan/commons/AppConfig.dart';
import 'package:yuanquan/commons/http/HttpManager.dart';
import 'package:yuanquan/routes/LoginPage.dart';

class SplashPage extends StatefulWidget {
  const SplashPage({super.key});

  @override
  State<StatefulWidget> createState() => _SplashPageState();
}

class _SplashPageState extends State<SplashPage> {
  @override
  Widget build(BuildContext context) {
    return const Image(
      image: AssetImage('assets/imgs/ic_splash_bg.png'),
      fit: BoxFit.cover,
    );
  }

  @override
  void initState() {
    super.initState();
    _initSomething();
    _gotoLogin();
  }

  void _initSomething() {
    //初始化 Http，
    HttpManager().init(
      baseUrl: AppConfig.SERVER_ADDR,
      connectTimeout: AppConfig.CONNECT_TIMEOUT,
      receiveTimeout: AppConfig.RECEIVE_TIMEOUT,
      interceptors: [
        // HeaderInterceptor(),
        LogInterceptor(),
      ],
    );
  }

  void _gotoLogin() async {
    await Future.delayed(Duration(seconds: 1)); // 等待3秒，模拟加载过程
    Navigator.pushReplacement(
      context,
      MaterialPageRoute(builder: (context) => const LoginPage()),
    );
  }
}